<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Sets formatterʼs timezone</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="intldateformatter.setpattern.html">« IntlDateFormatter::setPattern</a></li>
      <li style="float: right;"><a href="class.resourcebundle.html">ResourceBundle »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.intldateformatter.html">IntlDateFormatter</a></li>
    <li>Sets formatterʼs timezone</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="intldateformatter.settimezone" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">IntlDateFormatter::setTimeZone</h1>
  <h1 class="refname">datefmt_set_timezone</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.5.0, PHP 7, PHP 8, PECL intl &gt;= 3.0.0)</p><p class="refpurpose"><span class="refname">IntlDateFormatter::setTimeZone</span> -- <span class="refname">datefmt_set_timezone</span> &mdash; <span class="dc-title">Sets formatterʼs timezone</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-intldateformatter.settimezone-description">
  <h3 class="title">说明</h3>
  <p class="para">
   面向对象风格
  </p>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>IntlDateFormatter::setTimeZone</strong></span>(<span class="methodparam"><span class="type"><span class="type"><a href="class.intltimezone.html" class="type IntlTimeZone">IntlTimeZone</a></span>|<span class="type"><a href="class.datetimezone.html" class="type DateTimeZone">DateTimeZone</a></span>|<span class="type">string</span>|<span class="type">null</span></span> <code class="parameter">$timezone</code></span>): <span class="type"><span class="type">?</span><span class="type">bool</span></span></div>

  <p class="para rdfs-comment">
   过程化风格
  </p>
  <div class="methodsynopsis dc-description"><span class="methodname"><strong>datefmt_set_timezone</strong></span>(<span class="methodparam"><span class="type"><a href="class.intldateformatter.html" class="type IntlDateFormatter">IntlDateFormatter</a></span> <code class="parameter">$formatter</code></span>, <span class="methodparam"><span class="type"><span class="type"><a href="class.intltimezone.html" class="type IntlTimeZone">IntlTimeZone</a></span>|<span class="type"><a href="class.datetimezone.html" class="type DateTimeZone">DateTimeZone</a></span>|<span class="type">string</span>|<span class="type">null</span></span> <code class="parameter">$timezone</code></span>): <span class="type"><span class="type">?</span><span class="type">bool</span></span></div>


  <p class="para rdfs-comment">
   Sets the timezone used for the IntlDateFormatter.
   object.
  </p>

 </div>


 <div class="refsect1 parameters" id="refsect1-intldateformatter.settimezone-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt>
<code class="parameter">formatter</code></dt>

    <dd>

     <p class="para">
    The formatter resource.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">timezone</code></dt>

    <dd>

     <p class="para">
      The timezone to use for this formatter. This can be specified in the
      following forms:
     </p>
     

<ul class="itemizedlist">
 <li class="listitem">
  <p class="para">
   <strong><code>null</code></strong>, in which case the default timezone will be used, as specified in
   the ini setting <a href="datetime.configuration.html#ini.date.timezone" class="link">date.timezone</a> or
   through the function <span class="function"><a href="function.date-default-timezone-set.html" class="function">date_default_timezone_set()</a></span> and as
   returned by <span class="function"><a href="function.date-default-timezone-get.html" class="function">date_default_timezone_get()</a></span>.
  </p>
 </li>
 <li class="listitem">
  <p class="para">
   An <span class="classname"><a href="class.intltimezone.html" class="classname">IntlTimeZone</a></span>, which will be used directly.
  </p>
 </li>
 <li class="listitem">
  <p class="para">
   A <span class="classname"><a href="class.datetimezone.html" class="classname">DateTimeZone</a></span>. Its identifier will be extracted
   and an ICU timezone object will be created; the timezone will be backed
   by ICUʼs database, not PHPʼs.
  </p>
 </li>
 <li class="listitem">
  <p class="para">
   A <span class="type">string</span>, which should be a valid ICU timezone identifier.
   See <span class="function"><a href="intltimezone.createtimezoneidenumeration.html" class="function">IntlTimeZone::createTimeZoneIDEnumeration()</a></span>. Raw
   offsets such as <code class="literal">&quot;GMT+08:30&quot;</code> are also accepted.
  </p>
 </li>
</ul>

    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-intldateformatter.settimezone-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns <strong><code>null</code></strong> on success and <strong><code>false</code></strong> on failure.
  </p>
 </div>



 <div class="refsect1 examples" id="refsect1-intldateformatter.settimezone-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-2457">
   <p><strong>示例 #1 <span class="function"><strong>IntlDateFormatter::setTimeZone()</strong></span> examples</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />ini_set</span><span style="color: #007700">(</span><span style="color: #DD0000">'date.timezone'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'Europe/Amsterdam'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$formatter&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">IntlDateFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">create</span><span style="color: #007700">(</span><span style="color: #0000BB">NULL</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">NULL</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">NULL</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"UTC"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$formatter</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setTimeZone</span><span style="color: #007700">(</span><span style="color: #0000BB">NULL</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #DD0000">"NULL\n&nbsp;&nbsp;&nbsp;&nbsp;"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$formatter</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getTimeZone</span><span style="color: #007700">()-&gt;</span><span style="color: #0000BB">getId</span><span style="color: #007700">(),&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$formatter</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setTimeZone</span><span style="color: #007700">(</span><span style="color: #0000BB">IntlTimeZone</span><span style="color: #007700">::</span><span style="color: #0000BB">createTimeZone</span><span style="color: #007700">(</span><span style="color: #DD0000">'Europe/Lisbon'</span><span style="color: #007700">));<br />echo&nbsp;</span><span style="color: #DD0000">"IntlTimeZone\n&nbsp;&nbsp;&nbsp;&nbsp;"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$formatter</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getTimeZone</span><span style="color: #007700">()-&gt;</span><span style="color: #0000BB">getId</span><span style="color: #007700">(),&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$formatter</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setTimeZone</span><span style="color: #007700">(new&nbsp;</span><span style="color: #0000BB">DateTimeZone</span><span style="color: #007700">(</span><span style="color: #DD0000">'Europe/Paris'</span><span style="color: #007700">));<br />echo&nbsp;</span><span style="color: #DD0000">"DateTimeZone\n&nbsp;&nbsp;&nbsp;&nbsp;"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$formatter</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getTimeZone</span><span style="color: #007700">()-&gt;</span><span style="color: #0000BB">getId</span><span style="color: #007700">(),&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$formatter</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setTimeZone</span><span style="color: #007700">(</span><span style="color: #DD0000">'Europe/Rome'</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #DD0000">"String\n&nbsp;&nbsp;&nbsp;&nbsp;"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$formatter</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getTimeZone</span><span style="color: #007700">()-&gt;</span><span style="color: #0000BB">getId</span><span style="color: #007700">(),&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$formatter</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setTimeZone</span><span style="color: #007700">(</span><span style="color: #DD0000">'GMT+00:30'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$formatter</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getTimeZone</span><span style="color: #007700">());</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
NULL
    Europe/Amsterdam
IntlTimeZone
    Europe/Lisbon
DateTimeZone
    Europe/Paris
String
    Europe/Rome
IntlTimeZone Object
(
    [valid] =&gt; 1
    [id] =&gt; GMT+00:30
    [rawOffset] =&gt; 1800000
    [currentOffset] =&gt; 1800000
)

</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-intldateformatter.settimezone-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="intldateformatter.gettimezone.html" class="function" rel="rdfs-seeAlso">IntlDateFormatter::getTimeZone()</a> - Get formatterʼs timezone</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>